package com.sc.nft.hna.form;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.sc.nft.config.hna.HnaConfig;
import com.sc.nft.dto.UserHnaAccountCreateDTO;
import lombok.Data;

import java.util.Map;

@Data
public class R010TransForm extends BaseTransForm {

  public static final String[] encryptArr =
      new String[] {"merUserId", "mobile", "userName", "certNo"};
  public static final String[] verifyArr =
      new String[] {
        "version",
        "tranCode",
        "merOrderId",
        "merId",
        "charset",
        "signType",
        "resultCode",
        "errorCode",
        "userId"
      };
  public static final String[] submitArr =
      new String[] {
        "version",
        "tranCode",
        "merId",
        "merOrderId",
        "submitTime",
        "msgCiphertext",
        "signType",
        "signValue",
        "merAttach",
        "charset"
      };
  private static final long serialVersionUID = 4251219823057402869L;

  private String merUserId; // 商户用户唯一标识
  private String mobile; // 用户手机号
  private String userName; // 真实姓名
  private String certNo; // 身份证号
  private String tranCode = "R010";

  public static final String MAIN_URL = "https://ncount.hnapay.com/api/r010.htm";
  public static final String TRAN_CODE = "R010";

  @Override
  public String getEncryptJsonStr() {
    return getJsonStr(this, encryptArr);
  }

  @Override
  public String getVerifyJsonStr() {
    return getJsonStr(this, verifyArr);
  }

  @Override
  public String getSubmitJsonStr() {
    return getJsonStr(this, submitArr);
  }

  public static Map<String, Object> generateParam(
      long userId, HnaConfig hnaConfig, UserHnaAccountCreateDTO dto) {
    R010TransForm transForm = new R010TransForm();
    transForm.initCommonParams(TRAN_CODE, hnaConfig.getMerId(), IdWorker.getIdStr(), "");
    transForm.setMerUserId(String.valueOf(userId));
    transForm.setMobile(dto.getMobile());
    transForm.setUserName(dto.getRealName());
    transForm.setTranCode(TRAN_CODE);
    transForm.setCertNo(dto.getCertNo());
    return generateParam(transForm, hnaConfig);
  }
}
